package kr.hkit.PowerJava.chapter08.work;
/* 은행계좌
 * owner - 예금주
 * accountNumber - 계좌번호
 * balance - 예금잔액
 */
public class Programming6 {
   private String owner;
   private int accountNumber;
   private int balance;
   
public Programming6(String owner, int accountNumber, int balance){
	this.owner = owner;
	this.accountNumber = accountNumber;
	this.balance = balance;
}

public String getOwner() {
	return owner;
}

public void setOwner(String owner) {
	this.owner = owner;
}

public int getAccountNumber() {
	return accountNumber;
}

public void setAccountNumber(int accountNumber) {
	this.accountNumber = accountNumber;
}
public int getBalance() {
	return balance;
}
public void setBalance(int balance) {
	this.balance = balance;
}
/* 예금
 * @param amount 입금액
 */
 public void deposit(int amount){
	 balance += amount;
 }
public int withdraw(int amount){
	if (balance < amount || balance == 0){
		System.out.println("출금 불가 잔액 : "+balance);
		return -1;
	}else{
		balance -= amount;
		return amount;
	}
}
//현재 객체의 잔액에서 amount 만큼 otherAccount 계좌로 송금한다.
public int transfer(int amount, Programming6 otherAccount){
	if (balance < amount){
		System.out.println("잔액이 부족합니다. ");
	    return -1;
	}else{
		balance -= amount;
		otherAccount.setBalance(otherAccount.getBalance()+amount);
		return amount;
	}
}

@Override
public String toString() {
	return "예금주 [owner=" + owner + ",계좌번호 : " + accountNumber
			+ ", 잔액 : " + balance + "원]";
}


}
